<template>
  <div class="dialog-overlay" v-if="show">
    <div class="dialog-content">
      <div class="dialog-header">
        <h3>退出方式</h3>
        <button class="close-btn" @click="onClose">×</button>
      </div>
      <div class="dialog-body">
        <div class="radio-group">
          <label class="radio-item">
            <input 
              type="radio" 
              v-model="selectedOption" 
              :value="0"
              name="exitOption"
            >
            最小化到托盘，不退出程序
          </label>
          <label class="radio-item">
            <input 
              type="radio" 
              v-model="selectedOption" 
              :value="1"
              name="exitOption"
            >
            退出程序
          </label>
        </div>
        <label class="checkbox-item">
          <input 
            type="checkbox" 
            v-model="rememberChoice"
          >
          记住当前选择，下次不提示
        </label>
      </div>
      <div class="dialog-footer">
        <button class="btn btn-primary" @click="onConfirm">确定</button>
        <button class="btn" @click="onClose">关闭</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ExitDialog',
  data() {
    return {
      show: false,
      selectedOption: 0,
      rememberChoice: false
    }
  },
  methods: {
    showDialog() {
      this.show = true
    },
    onConfirm() {
      window.electronAPI.sendExitChoice({
        choice: this.selectedOption,
        remember: this.rememberChoice
      })
      this.show = false
    },
    onClose() {
      this.show = false
    }
  },
  mounted() {
    window.electronAPI.onShowExitDialog(() => {
      this.showDialog()
    })
  }
}
</script>

<style scoped>
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.dialog-content {
  background: white;
  border-radius: 8px;
  width: 400px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.dialog-header {
  padding: 16px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-header h3 {
  margin: 0;
  font-size: 16px;
  color: #333;
}

.close-btn {
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  color: #999;
  padding: 0;
  line-height: 1;
}

.dialog-body {
  padding: 20px 16px;
}

.radio-group {
  margin-bottom: 16px;
}

.radio-item {
  display: block;
  margin-bottom: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #333;
  font-size: 14px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: #333;
  font-size: 14px;
}

.dialog-footer {
  padding: 16px;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn {
  padding: 8px 16px;
  border-radius: 4px;
  border: 1px solid #ddd;
  background: white;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s;
}

.btn:hover {
  border-color: #0052d9;
  color: #0052d9;
}

.btn-primary {
  background: #0052d9;
  color: white;
  border-color: #0052d9;
}

.btn-primary:hover {
  background: #0047c3;
  border-color: #0047c3;
  color: white;
}

input[type="radio"],
input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}
</style> 